package com.test;

import java.util.Arrays;

public class LeetcodeTest6 {
    public static void main(String[] args) {
//        int[] ints = new int[1];
//        ints[0]=66;
                System.out.println(new LeetcodeTest6().convert("LEETCODEISHIRING", 3));
        System.out.println(new LeetcodeTest6().convert("LEETCODEISHIRING", 4));
    }

    /**
     * 先整一个数组,往里塞,然后打印数组
     *
     * @param s
     * @param numRows
     * @return
     */
    public String convert(String s, int numRows) {
        int x = (s.length() / 2 * numRows - 2) * (numRows - 1);
        int y = (s.length() % 2 * numRows - 2);
        int column;
        if (y <= numRows) {
            column = x + 1;
        } else {
            column = x + y % numRows;
        }

        int rowIndex = 0;
        int columnIndex = 0;
        char[][] charArr = new char[numRows][columnIndex];

        boolean flag = true;
        for (int i = 0; i < s.length(); i++) {
            char c = s.charAt(i);
            int count = numRows;
            int count2 = numRows - 2;
            if (flag) {
                for (int j = 1; j <= count; j++) {
                    charArr[rowIndex][columnIndex]  = c;
                    rowIndex++;
                    if (j == count) {
                        flag = false;
                    }
                }
            } else {
                for (int j = 1; j <= count2; j++) {
                    charArr[rowIndex][columnIndex] = c;
                    rowIndex--;
                    columnIndex++;
                    if (j == count2) {
                        flag = true;
                    }
                }
            }
        }
        String s1 = Arrays.toString(charArr);
        return s1;
    }
}
